home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / fd.s5 / openfile.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  748b  |  37 lines

  1. /*
  2.  *    openfile  <socket-descriptor-number>  <filename>  <mode>
  3.  *
  4.  * Open the specified file using the specified mode.
  5.  * Return the open file descriptor on the specified socket descriptor
  6.  * (which the invoker has to set up before exec'ing us).
  7.  * We exit() with a value of 0 if all is OK, otherwise we pass back the
  8.  * errno value as our exit status.
  9.  */
  10.  
  11. main(argc, argv)
  12. int    argc;
  13. char    *argv[];
  14. {
  15.     int        fd;
  16.     extern int    errno;
  17.     extern char    *pname;
  18.  
  19.     pname = argv[0];
  20.  
  21.     if (argc != 4)
  22.         err_quit("openfile <sockfd#> <filename> <mode>");
  23.  
  24.     /*
  25.      * Open the file.
  26.      */
  27.  
  28.     if ( (fd = open(argv[2], atoi(argv[3]))) < 0)
  29.         exit( (errno > 0) ? errno : 255 );
  30.  
  31.     /*
  32.      * And pass the descriptor back to caller.
  33.      */
  34.  
  35.     exit( sendfile(atoi(argv[1]), fd) );
  36. }
  37.